let isBaseUrl = 1; //1 0为测试域名 1为正式域名 
let BASE_URL = isBaseUrl ? 'https://jxjsservice.jxfit.cn' : 'http://192.168.1.114:9091';
// let BASE_URL = isBaseUrl ? 'https://jxjsservice.jxfit.cn' : 'http://192.168.1.103:9091';

const myRequest = (options) => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: (options.baseUrl || BASE_URL) + options.url,
      method: options.method || 'GET',
      data: options.data || {},
      header: options.header || {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      // header: options.header || {'Content-Type':'application/json'},
      success: (res) => {
        if (res.data.result !== 200) {
          const error = new Error('有问题');
          reject(error);
          return uni.showToast({
            // title: '接口异常~',
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }
        resolve(res)
      },
      fail: (err) => {
        uni.showToast({
          title: '请求接口失败',
          icon: "loading"
        })
        reject(err)
      }
    })
  })
}
const showToast = (title, icon = 'success', duration = 1500) => {
  return uni.showToast({
    title,
    icon,
    duration,
  });
}

module.exports = {
  myRequest,
  showToast,
}



// {
// 	"bId": 1,
// 	"memberId": 45,
// 	"periodList": [{
// 		"bfChange": 0,

// 		"muscleChange": 0,
// 		"name": "string",
// 		"periodCycle": 0,
// 		"periodFrequency": 0,
// 		"periodNum": 0,
// 		"remark": "string",
// 		"trainingPonit": [
// 			"string"
// 		],
// 		"trainingProject": [
// 			"string"
// 		],
// 		"weightChange": 0
// 	}],
// 	"trainingCycle": 12,
// 	"trainingFrequency": 23,
// 	"trainingTarget": [
// 		"减脂", "增肌"
// 	],
// 	"userId": 47
// }
